#ifndef _XBASE_STAT_HPP
#define _XBASE_STAT_HPP

#include <stdint.h>
#include <string>
#include <iostream>
#include <fstream>

#include "xbase_utility.hpp"

namespace xbase
{
	struct scan_stat
	{
		scan_stat()
			: m_local_process_time(0), m_scan_open_time(0),
			  m_scan_next_time(0), m_scan_record_count(0), m_scan_open_times(0), m_scan_next_times(0)
		{
			
		}

		void reset()
		{
			m_local_process_time = 0;
			m_scan_open_time = 0;
			m_scan_open_times = 0;
			m_scan_next_time = 0;
			m_scan_next_times = 0;
			m_scan_record_count = 0;
		}

		uint64_t m_local_process_time;

		uint64_t m_scan_open_time;
		uint64_t m_scan_next_time;

		unsigned m_scan_record_count;
		unsigned m_scan_open_times;
		unsigned m_scan_next_times;
	};

	struct stat
	{
		stat(const std::string &stat_file_name) : outf(stat_file_name.c_str(),std::ios_base::app)
		{
			outf << "Time"
				<< "\t" << "m_local_process_time"
				<<"\t"<<"m_scan_open_time"
				<<"\t"<<"m_scan_open_times"
				<<"\t"<<"m_scan_next_time"
				<<"\t"<<"m_scan_next_times"
				<<"\t"<<"m_scan_record_count"
				<<std::endl;
			outf.flush();
		}

		void reset()
		{
			m_scan_stat.reset();
		}

		void write()
		{
			outf << dump_timestamp(cur_micro_seconds())
				<< "\t" << m_scan_stat.m_local_process_time
				<< "\t" << m_scan_stat.m_scan_open_time
				<< "\t" << m_scan_stat.m_scan_open_times
				<< "\t" << m_scan_stat.m_scan_next_time
				<< "\t" << m_scan_stat.m_scan_next_times
				<< "\t" << m_scan_stat.m_scan_record_count
				<<std::endl;

			outf.flush();
		}

		std::ofstream outf;
		scan_stat m_scan_stat;
	};
}

#endif
